<?php
class Job_template extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('job_template_model');
	}

	public function index($pn=1)
	{

		$data['job_template'] = $this->job_template_model->get_job_template();

		$this->load->library('pagination');

		$config['base_url'] = 'http://localhost/i-webmonitor/index.php/job_template/index/';
		$config['total_rows'] = count($this->job_template_model->get_job_template());
		$config['per_page'] = 2;
		$config['uri_segment'] = 3;
		$config['first_link'] = 'First';
		$config['last_link'] = 'Last';
		$config['first_tag_open'] = '<div>';
		$config['first_tag_close'] = '</div>';
		$config['last_tag_open'] = '<div>';
		$config['last_tag_close'] = '</div>';

		$this->pagination->initialize($config);
		$data['job_template'] = $this->job_template_model->get_page_job_template($config['per_page'],$this->uri->segment(3));




		$this->load->view('templates/header', $data);
		$this->load->view('job_template/index', $data);
		$this->load->view('templates/footer');
	}

	public function view($id)
	{
		$data['job_template'] = $this->job_template_model->get_job_template($id);

		$this->load->view('templates/header', $data);
		$this->load->view('job_template/view', $data);
		$this->load->view('templates/footer');
	}
	public function create()
	{
		$this->load->helper('form');
		$this->load->library('form_validation');

		$this->form_validation->set_rules('id', 'id', 'required');
		$this->form_validation->set_rules('url', 'url', 'required');

		if ($this->form_validation->run() === FALSE)
		{
			$this->load->view('templates/header');
			$this->load->view('job_template/create');
			$this->load->view('templates/footer');

		}
		else
		{
			$this->job_template_model->insert_job();
			$this->load->view('job_template/succeed');
		}
	}
	public function edit($id)
	{

		if ($id === FALSE)
		{
			$this->load->view('templates/header');
			$this->load->view('job_template');
			$this->load->view('templates/footer');

		}
		else
		{
			$this->job_template_model->edit_job();
			$this->load->view('job_template/succeed');
		}
	}
	public function delete($id)
	{

		$this->job_template_model->delete_job($id);

	}
	public function datagrid()
	{
		$data['job_template'] = $this->job_template_model->get_job_template();
		
		$this->load->view('job_template/datagrid', $data);

	}
}
